package com.application.lucky.utils;

import android.content.res.Resources;
import android.support.v4.content.ContextCompat;

import com.application.lucky.Lucky;

/**
 * create by liulp
 * on 2019-11-04 20:33
 */
public final class UIResUtils {
    public static int getInteger(int resId) {
        Resources res = Lucky.getApplication().getResources();
        return res.getInteger(resId);
    }

    public static String getString(int resId) {
        Resources res = Lucky.getApplication().getResources();
        return res.getString(resId);
    }

    public static String[] getStringArray(int resId) {
        Resources res = Lucky.getApplication().getResources();
        return res.getStringArray(resId);
    }

    public static String getString(int resId, Object... items) {
        Resources res = Lucky.getApplication().getResources();
        Object[] param = new Object[items.length];

        int i = 0;
        for (Object resObj : items) {
            if (resObj instanceof Integer) {
                Integer resV = ((Integer) resObj).intValue();
                if (resV > 0x7f000000) {
                    param[i] = getString(resV);
                } else {
                    param[i] = resObj;
                }
            } else {
                param[i] = resObj;
            }

            i++;
        }
        return String.format(res.getString(resId), param);
    }

    public static int getColor(int resId) {
        return ContextCompat.getColor(Lucky.getApplication(), resId);
    }
}
